package com.sc.nft.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.OrderDetailExportRequest;
import com.sc.nft.admin.request.OrderExportRequest;
import com.sc.nft.admin.request.TempRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.TempOrderDetail;
import com.sc.nft.entity.vo.OrderDetailListVO;
import com.sc.nft.entity.vo.OrderSimpleVO;
import com.sc.nft.enums.OrderExportTypeEnum;
import com.sc.nft.service.TempOrderDetailService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;


/**
 * @author 朱梦晨
 * @Description: 订单/订单详情导出
 * @date 2024-08-02
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/temp/order")
@Api(tags="首发订单导出模块")
public class TempOrderDetailController {


    private final TempOrderDetailService tempOrderDetailService;


    @PostMapping(value = "/orderExport", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "首发订单导出", notes = "首发订单导出", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result tempOrderExcel(@Valid @RequestBody OrderExportRequest request){

        return Result.success(tempOrderDetailService.saveTempOrderDetail(OrderExportTypeEnum.ORDER.getCode(),
                request.getProductId(),null,null));
    }

    @PostMapping(value = "/orderDetailExport", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "首发订单明细导出", notes = "首发订单明细导出", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result tempOrderDetailExcel(@Valid @RequestBody OrderDetailExportRequest request){

        return Result.success(tempOrderDetailService.saveTempOrderDetail(OrderExportTypeEnum.ORDER_DETAIL.getCode(),
                request.getProductId(),request.getPayTimeFrom(),request.getPayTimeTo()));
    }


    @PostMapping(value = "/download", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "首发订单导出下载", notes = "首发订单导出下载", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<OrderSimpleVO>> findTempOrderList(@Valid @RequestBody TempRequest request){
        List<TempOrderDetail> tempOrderDetailList = tempOrderDetailService.findTempOrderDetailList(request.getExportRecordsId());
        List<OrderSimpleVO> orderSimpleVOS = BeanUtil.copyToList(tempOrderDetailList, OrderSimpleVO.class);
        return Result.success(orderSimpleVOS);
    }

    @PostMapping(value = "/detailDownload", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "首发订单明细导出下载", notes = "首发订单明细导出下载", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<OrderDetailListVO>> findTempOrderDetailList(@Valid @RequestBody TempRequest request){
        List<TempOrderDetail> tempOrderDetailList = tempOrderDetailService.findTempOrderDetailList(request.getExportRecordsId());
        List<OrderDetailListVO> orderDetailListVOS = BeanUtil.copyToList(tempOrderDetailList, OrderDetailListVO.class);
        return Result.success(orderDetailListVOS);
    }



}
